<script>
	import {
		ajax,
		ApiUrl
	} from "api/apis.js"
	export default {
		data() {
			return {
				current_version: "",
				appName: "",
				update_version: ""
			}
		},
		onLaunch: function() {
			const info = plus.push.getClientInfo();
			uni.setStorageSync("deviceId", info.clientid);
			const _self = this;
			const _handlePush = function(message) {
				uni.navigateTo({
					url: "./messagelist/messagelist"
				});
			};
			plus.push.addEventListener("click", _handlePush);
			plus.push.addEventListener("receive", _handlePush);
			
			
			let _this = this
			plus.runtime.getProperty(plus.runtime.appid, function(info) {
				console.log(info)
				_this.current_version = info.version
				_this.appName = info.name
			});
			console.log(_this.current_version,_this.appName);
			ajax({
				url: '/update/getNow?name='+_this.appName,
				method: "GET",
				success(res) {
					console.log(res)
					let update = res.data.data.update;
					let pkgUrl = res.data.data.pkgUrl;
					_this.update_version = res.data.data.version;
					if (res.statusCode == 200 && res.data.state === 1) {
						uni.showModal({ //提醒用户更新  
							title: "更新提示",
							content: '请更新',
							success: (res) => {
								if (res.confirm) {
									 console.log('用户点击确定')
									plus.runtime.openURL(res.data.pkgUrl);
								}else if(res.cancel){
									 console.log('用户点击取消')
								}
							}
						})
					}
				}
			});
		},
		onShow: function() {
			console.log("App Show");
			
		},
		onHide: function() {
			console.log("App Hide");
		}
	};
</script>

<style>
	/*每个页面公共css */
	.app,
	body,
	html {
		height: 100%;
	}

	.uni-page-body {
		height: 100%;
	}

	.uni-page-wrapper {
		height: 100%;
	}
</style>
